package com.hanlin.work;

import com.hanlin.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

import java.io.IOException;

/**
 * 描述：work模式
 * @author:hl.yuan
 * @date:2021-03-13
 */
public class SendRabbitMQ {

    @Test
    public void send() throws IOException {
        // 获取connection连接
        Connection connection = RabbitUtils.getConnection();

        Channel channel = connection.createChannel();
        //参数1: 是否持久化  参数2:是否独占队列 参数3:是否自动删除  参数4:其他属性
        channel.queueDeclare("hello", true, false, false, null);
        for (int i = 0; i < 30; i++) {
            channel.basicPublish("", "hello", null, (i+"====>:我是消息").getBytes());
        }
        // 关闭连接
        RabbitUtils.closeConnection(channel,connection);
    }

}
